home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xml;
-
- import com.extensibility.plugin.PluginRegistry;
- import com.extensibility.plugin.api.URIScheme;
- import com.extensibility.plugin.api.URISchemeAdapter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.Reader;
- import java.io.Writer;
- import java.util.Vector;
-
- public class URIFileScheme extends URISchemeAdapter {
- private File file;
-
- public static void registerPlugin(PluginRegistry var0) {
- var0.registerPlugin("URIScheme10", Class.forName("com.extensibility.xml.URIFileScheme"), "URIFileScheme", 65537);
- }
-
- public URIFileScheme() {
- this.file = null;
- }
-
- public URIFileScheme(File var1) {
- this.file = var1;
- }
-
- public void registerSchemes(URIScheme.Manager var1) {
- var1.registerScheme("file", Class.forName("java.io.File"), this);
- }
-
- public URIScheme construct(String var1, String var2) {
- if (var2.startsWith("file://")) {
- var2 = var2.substring(7);
- } else {
- var2 = var2.substring(5);
- }
-
- var2 = var2.replace('/', File.separatorChar);
- return new URIFileScheme(new File(var2));
- }
-
- public URIScheme construct(Object var1) {
- return new URIFileScheme((File)var1);
- }
-
- public URIScheme construct(String var1) {
- var1 = var1.replace('/', File.separatorChar);
- File var2 = new File(this.file.getParent(), var1);
- return new URIFileScheme(var2);
- }
-
- public static Vector getFileParents(File var0) {
- Vector var1 = new Vector();
-
- String var2;
- while((var2 = var0.getParent()) != null) {
- var0 = new File(var2);
- var1.insertElementAt(var0, 0);
- }
-
- return var1;
- }
-
- public String computeRelative(URIScheme var1) {
- URIFileScheme var2 = (URIFileScheme)var1;
- File var3 = var2.file;
- Vector var4 = getFileParents(var2.file);
- Vector var5 = getFileParents(this.file);
- int var7 = 0;
- boolean var8 = true;
-
- while(var7 < var5.size() && var7 < var4.size() && var8) {
- File var6 = (File)var5.elementAt(var7);
- File var9 = (File)var4.elementAt(var7);
- var8 = var6.equals(var9);
- if (var8) {
- ++var7;
- }
- }
-
- StringBuffer var12 = new StringBuffer();
- if (var7 > 0) {
- int var10;
- for(var10 = var7; var7 < var4.size(); ++var7) {
- var12.append("../");
- }
-
- while(var10 < var5.size()) {
- File var11 = (File)var5.elementAt(var10);
- var12.append(var11.getName());
- var12.append('/');
- ++var10;
- }
-
- var12.append(this.file.getName());
- } else {
- var12.append(this.file.getAbsolutePath().replace(File.separatorChar, '/'));
- if (var12.charAt(0) != '/') {
- var12.insert(0, '/');
- }
- }
-
- return var12.toString();
- }
-
- public URIScheme toParent() {
- URIFileScheme var1 = null;
- String var2 = this.file.getParent();
- if (var2 != null) {
- var1 = new URIFileScheme(new File(var2));
- }
-
- return var1;
- }
-
- public String getScheme() {
- return "file";
- }
-
- public URIScheme renameTo(String var1) {
- File var2 = new File(this.file.getParent(), var1);
- URIFileScheme var3 = null;
- if (this.file.renameTo(var2)) {
- var3 = new URIFileScheme(var2);
- }
-
- return var3;
- }
-
- public long getLength() {
- return this.file.length();
- }
-
- public InputStream createInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- public Reader createReader() throws IOException {
- return new FileReader(this.file);
- }
-
- public Writer createWriter() throws IOException {
- return new FileWriter(this.file);
- }
-
- public OutputStream createOutputStream() throws IOException {
- return new FileOutputStream(this.file);
- }
-
- public boolean exists() {
- return this.file != null && this.file.exists() && !this.file.isDirectory();
- }
-
- public boolean isReadOnly() {
- boolean var1;
- if (!this.file.exists()) {
- var1 = false;
- } else {
- var1 = !this.file.canWrite();
- }
-
- return var1;
- }
-
- public boolean equals(URIScheme var1) {
- URIFileScheme var2 = (URIFileScheme)var1;
- return this.file.equals(var2.file);
- }
-
- public int compareTo(URIScheme var1) {
- URIFileScheme var2 = (URIFileScheme)var1;
- return this.file.getAbsolutePath().compareTo(var2.file.getAbsolutePath());
- }
-
- public String getShortName() {
- return this.file.getName();
- }
-
- public String getFullPath() {
- String var1 = this.file.getAbsolutePath();
- String var2 = var1.replace(File.separatorChar, '/');
- StringBuffer var3 = new StringBuffer("file://");
- if (!var2.startsWith("/")) {
- var3.append("/");
- }
-
- var3.append(var2);
- return var3.toString();
- }
- }
-